<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/component/commonTagLib.jsp"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="renderer" content="webkit">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no,minimal-ui">
<link href="http://cdn.bootcss.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet">

<style type="text/css">
.main {
	background-color:#000;
	color:#F00;
	padding:10px 20px;
	border:1px solid #aaa;
	position:fixed;
	width:100%;
	bottom:-1px;
	left:0px;
	filter:alpha(opacity=70);
	-moz-opacity:0.7;
	-khtml-opacity: 0.7;
	opacity: 0.7;}
.contre{width:250px;margin: auto;}

</style>
<%@ include file="/WEB-INF/component/commonCSS.jsp"%>
</head>
<body>
<div class="box box-primary" id="more" style="width:110px;height:35px;background-color:#222c32;position:absolute;z-index:9999;left:850px;top:100px;display:none;font-size:12px;border-top-color:#222c32;">
            <div class="box-body home-message" id="moreOp" >
            </div>
        </div>
	<section class="content-header">
		<h1>企业资111质管理</h1>
		<ol class="breadcrumb">
			<li><a href="${ctx}/home.jsp"><i class="fa fa-home"></i>首页</a></li>
			<li class="active"><a href="#">企业库</a></li>
			<li class="active"><a href="#">企业库资质管理</a></li>
		</ol>
		<div class=" box box-success"></div>
	</section>
	<section class="content">
<div id="wrapper" >
<div id="content" >
<script id="test" type="text/html">
   {{each rows as row i}}
			<div class="col-xs-6 col-lg-4 hei" >
				<div class="wrapper2 ">
								<div class="dropdown">
								   <button type="button" class="btn dropdown-toggle" id="dropdownMenu1" 
								      data-toggle="dropdown">编辑<span class="caret"></span>
								   </button>
								   <ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1">
								      <li role="presentation" >
								         <a role="menuitem" tabindex="-1" href="javascript:changeStatus('{{row.status}}','{{row.compprofileId}}')">{{row.status | formatStatusEdit}}</a>
								         <a role="menuitem" tabindex="-1" href="javascript:edit('{{row.compprofileId}}','{{row.profileCode}}','{{row.profileName}}','{{row.profileType}}','{{row.profileStarttimeStr}}','{{row.profileEndtimeStr}}','{{row.profilePicAddr}}','{{row.remarks}}','{{row.status}}')">编辑</a>
								         <a role="menuitem" tabindex="-1" href="${ctx}/stdCompprofile/toStdCompprofileLogJsp.html?compprofileId={{row.compprofileId}}">维护记录</a>
								      </li>
								   </ul>
								</div>
					<a id=""  href="javascript:showImg('{{row.profilePicAddr}}');" ><img class="img-responsive" src="${ctx}/{{row.profilePicShortcutAddr}}"></a>
					<div class="row">
						<div class="col-md-12">
							<p class="pull-left">
								<div class="productInfo" >&nbsp;资质编号:<span class="productInfo" name="profileCode" >{{row.profileCode}}</span></div>
							</p>
						</div>
					</div>
					<div class="row">
						<div class="col-md-12">
							<p class="pull-left">
								<div class="productInfo" >&nbsp;资质名称:<span class="productInfo" name="profileName" >{{row.profileName}}</span></div>
							</p>
						</div>
					</div>
					<div class="row">
						<div class="col-md-12">
							<p class="pull-left">
								<div class="productInfo" >&nbsp;资质类型:<span class="productInfo" name="profileType" >{{row.profileType}}</span></div>
							</p>
						</div>
					</div>
					<div class="row">
						<div class="col-md-12">
							<p class="pull-left">
								<div class="productInfo" >&nbsp;资质有效期开始日期:<span class="productInfo" name="profileStarttimeStr" >{{row.profileStarttimeStr}}</span></div>
						    </p>
						</div>
					</div>
					<div class="row">
						<div class="col-md-12">
							<p class="pull-left">
								<div class="productInfo" >&nbsp;资质有效期截至日期:<span class="productInfo" name="profileEndtimeStr" >{{row.profileEndtimeStr}}</span></div>
						    </p>
						</div>
					</div>
					<div class="row">
						<div class="col-md-12">
							<p class="pull-left">
								<div class="productInfo" >&nbsp;状态:<span class="productInfo" name="status" >{{row.status | formatStatus}}</span></div>
							</p>
						</div>
					</div>
					<div class="row">
						<div class="col-md-12">
							<p class="pull-left">
								<div class="productInfo" >&nbsp;备注:<span class="productInfo" name="remarks" >{{row.remarks}}</span></div>
							</p>
						</div>
					</div>
					
				</div>
			</div>
 {{/each}}
		</script>	
		</div>
		</div>
	<div class="main">
 		 <div class="contre">
			<label id="addNew" class="btn btn-default btn-sm">新&nbsp;增</label>
			<a href="${ctx}/stdCompprofile/toStdCompprofileList.html" class="btn btn-default btn-sm">返&nbsp;回</a>
   		 </div>
	</div>
 </section>
 <div class="row productall">
	      <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
			<div class="modal-dialog">
            	<div class="modal-content">
                	<div class="modal-header bg-primary">
                    	<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    	<h5 class="modal-title" id="exampleModalLabel">企业资质</h5>
                    </div>
                    <form role="form" class="form-horizontal" id="FormSubmit" action="${ctx}/stdCompprofile/toStdCompprofileAdd.html" enctype="multipart/form-data" method="post">
            	<input type="hidden" name="compId" id="compId" value="${compId }">
            	<input type="hidden" name="compprofileId" id="compprofileId" >
            	<input type="hidden" name="status" id="status" value="1">
                 <div class="box-body"> 
                    <div class="form-group form-group-xs">
                        <label class="col-sm-5 text-right"><span class="required">*</span>企业资质编码：</label>
                        <div class="col-sm-4 text-left">
                            <input class="form-control" placeholder="企业资质编码" type="text" name="profileCode" id="profileCode" maxlength="100" value="" >
                        </div>
                    </div>
                    <div class="form-group form-group-xs">
                        <label class="col-sm-5 text-right"><span class="required">*</span>企业资质名称：</label>
                        <div class="col-sm-4 text-left">
                            <input class=" form-control" placeholder="企业资质名称" name="profileName" id="profileName" type="text" maxlength="64" value="">
                        </div>
                    </div>
                    <div class="form-group form-group-xs">
                        <label class="col-sm-5 text-right"><span class="required">*</span>企业资质类型：</label>
                        <div class="col-sm-4 text-left">
                            <input class="form-control" placeholder="企业资质类型" type="text" name="profileType" id="profileType" maxlength="4" value="" >
                        </div>
                    </div>
                    <div class="form-group form-group-xs">
                        <label class="col-sm-5 text-right"><span class="required">*</span>企业资质有效期始：</label>
                        <div class="col-sm-4 text-left">
                             <input class=" form-control" placeholder="企业资质有效期始" name="profileStarttime" id="profileStarttime" type="text" maxlength="128" value=""readonly="readonly" data-provide="datepicker" data-date-fmt="yyyy-MM-dd" placeholder="yyyy-MM-dd">
                        </div>
                    </div>
                     <div class="form-group form-group-xs">
                        <label class="col-sm-5 text-right"><span class="required">*</span>企业资质有效期止：</label>
                        <div class="col-sm-4 text-left">
                             <input class=" form-control" placeholder="企业资质有效期止" name="profileEndtime" id="profileEndtime" type="text" maxlength="128" value=""readonly="readonly" data-provide="datepicker" data-date-fmt="yyyy-MM-dd" placeholder="yyyy-MM-dd">
                        </div>
                    </div>
                    <div class="form-group form-group-xs">
                        <label for="acctApprovalPicDir" class="col-sm-5 text-right"><span class="required">*</span>资质图片地址：</label>
                         <div style="width:0px;height:0px;overflow:hidden;">
                                    <input id="profilePicAddr" name="licence" type="file" value="" style="display:inline-block;" />
                                </div>
                                <a href="javascript:selectImg();" style="display:inline-block;">上传</a>
                                <span id="addLook"></span>
                                <%-- <a href="javascript:showImg('${bankAcctInfo.acctApprovalPicDir}');" style="display:inline-block;">查看</a> --%>
                    </div>
                    <div class="form-group form-group-xs">
                        <label class="col-sm-5 text-right">备注：</label>
                        <div class="col-sm-4 text-left">
                            <input class="form-control" placeholder="备注" type="text" name="remarks" id="remarks" maxlength="256" value="" >
                        </div>
                    </div>
                </div> 
            </form>
                    <div class="modal-footer" style="text-align: center;">
                     <input hidden="true" id="spid"/>
           			   <input hidden="true" id="spfatherid"/>
                        <button type="button" class="btn btn-primary btn-sm" id="submitDicCompType" onclick="save();">保&nbsp;存</button>
                        <button type="button" class="btn btn-danger btn-sm" data-dismiss="modal" id="closeDicCompType">关&nbsp;闭</button>
                    </div>
                </div>
            </div>
        </div>
	</div>
<%@ include file="/WEB-INF/component/commonJS.jsp" %>
    <script src="${ctx}/lib/plugins/daterangepicker/moment.js"></script>
    <script src="${ctx}/lib/plugins/daterangepicker/daterangepicker.js"></script>

<script type="text/javascript">
/*格式化启用/停用 下拉编辑*/
template.helper('formatStatusEdit', function(data) {
	return data == 1 ? "停用" : "启用";
});	
/*格式化启用/停用 */
template.helper('formatStatus', function(data) {
	return data == 1 ? "启用" : "停用";
});	
	$(function() {
		var rows = 3;//一页展示多少条
		var page = 1;//当前页数
		var records = 0;//总条目
		var postData = {"rows":rows,"page":page};

		//停用启用
		$('#showOperate').children().eq(0).bind("click", function() {
			alert("WO " + $('#showOperate').children().eq(0).html());
		})
		getList(postData);
		
	    $(window).scroll(function() {
            console.log( $(document).scrollTop());// 获取垂直滚动的距离
            if ($(document).scrollTop() >= $(document).height() - $(window).height()) {
            	page++;
            	if (page <=Math.ceil(records/rows)) {
            		postData.page=page;
            		getList(postData);
            	} 
            }
         });
		   
		function getList(postData){
			$.post('getStdCompprofileListData.html?compId=${compId}',
					postData, function(result) {
						console.log(result);
						if (result.success) {
							var html = template('test', result);
							$('#content').append(html);
							records=result.records;  //总条数
						} else {
							$.HN.message.alert("数据获取失败", '信息', 'error');
						}
					}, "json");
		}
})
	
	function changeStatus(status,compprofileId) {
		var msg = status == 1 ? "停用" : "启用";//页面提示逻辑
		var statu = status == 1 ? 0:1;//后台数据逻辑
		$.HN.message.confirm("确定吗"+msg+"？", '', '').on(function(e) {
			if (e) {
				$.post('updateStatus.html', {
					"status" : statu,"compprofileId":compprofileId
				}, function(result) {
					if (result.success) {
						document.location.reload();
						$.HN.message.alert(result.msg, '信息', 'success');
						//TODO重新刷新页面
						$('#exampleModal').modal('hide');
					} else {
						$.HN.message.alert(result.msg, '信息', 'error');
					}
				}, "json");
			}
		});
	}
	 $('#addNew').click(function () {
			$('#compprofileId').val("");
		 	$('#profileCode').val("");
			$('#profileName').val("");
			$('#profileType').val("");
			$('#profileStarttime').val("");
			$('#profileEndtime').val("");
			$('#profilePicAddr').val("");
			$('#remarks').val("");
			$('#addLook').html("");
  	        $('#exampleModalLabel').html("企业资质新增");
            $('#exampleModal').modal({
                 keyboard: true
             });
         });
	function edit(id, code,name,type,startTime,endTime,strPath,remark,status) {
		$('#compprofileId').val("");
		$('#profileCode').val("");
		$('#profileName').val("");
		$('#profileType').val("");
		$('#profileStarttime').val("");
		$('#profileEndtime').val("");
		$('#acctApprovalPicDir').val("");
		$('#remarks').val("");
		$('#status').val("");
		$('#exampleModalLabel').html("企业资质编辑");
		$('#exampleModal').modal({
			keyboard : true
		});
		$('#compprofileId').val(id);
		$('#profileCode').val(code);
		$('#profileName').val(name);
		$('#profileType').val(type);
		$('#profileStarttime').val(startTime);
		$('#profileEndtime').val(endTime);
		$('#remarks').val(remark);
		$('#status').val(status);
		$('#addLook').html("<a href=\"javascript:showImg('"+strPath+"');\" style=\"display:inline-block;\">查看</a>");
		//$('#profilePicAddr').val(strPath);
		
	}
	
	 function save(){
	    	if(!validateBase()){
	    		return;
	    	}
	    	$.HN.message.confirm('确定要保存吗？', '', '').on(function (e) {
	            if (e) {
	          	  $("#FormSubmit").ajaxSubmit({
	          		  dataType : "json",
	        			  timeout: 10000,
	          		  success: function(result,statusText) {
	              		if(result.success){
	              			document.location.reload();
	      	     			$.HN.message.alert('保存成功！', '提示信息', 'success');
	              		}else{
	              			$.HN.message.alert(result.msg
									|| "提交失败！", "消息", "error");
	              		}
	          		  }
	    	   	  });
	          	  } 
	  	  });
	    }
	    function selectImg() {
	    	$('#profilePicAddr').click();
	    }
	    function back(){
	    	window.location.href="${ctx}/stdCompprofile/toStdCompprofileList.html";
	    }
	    
	    function showImg(imgPath) {
			var url = "/medstgmini/acctInfo/toImg.html";
			$.HN.dialog.open({
				"id" : "showImg",
				"title" : "许可证",
				"url" : url,
				"data" : {
					"imgPath" : imgPath
				},
				"width" : 800,
				"height" : 400,
				"closefunc" : function(params) {
					if (params) {

					}
				}
			});
		}
	    
		function validateBase() {
	 		var profileCode = $.trim($("#profileCode").val());
			if (profileCode == null || profileCode == "") {
				$.HN.message.alert("请输入企业资质编码！", "消息", "warn");
				return false;
			} else if (!/^[a-zA-Z0-9_]+$/.test(profileCode)) {
				$.HN.message.alert("企业资质编码只能由字母数字下划线组成！", "消息", "warn");
				return false;
			}
			$("#profileCode").val(profileCode);

			var profileName = $.trim($("#profileName").val());
			if (profileName == null || profileName == "") {
				$.HN.message.alert("请输入企业资质名称！", "消息", "warn");
				return false;
			}
			$("#profileName").val(profileName);
			
			var profileType = $.trim($("#profileType").val());
			if (profileType == null || profileType == "") {
				$.HN.message.alert("请选择企业资质类型！", "消息", "warn");
				return false;
			}
			$("#profileType").val(profileType);

			var profileStarttime = $.trim($("#profileStarttime").val());
			if (profileStarttime == null || profileStarttime == "") {
				$.HN.message.alert("请选择企业资质有效期始！", "消息", "warn");
				return false;
			}
			$("#profileStarttime").val(profileStarttime);
			

			
			var profileEndtime = $.trim($("#profileEndtime").val());
			if (profileEndtime == null || profileEndtime == "") {
				$.HN.message.alert("请选择企业资质有效期止！", "消息", "warn");
				return false;
			} 
			$("#profileEndtime").val(profileEndtime);
			
			return true;
			
		}
	</script>
</body>
</html>